var ming = document.getElementById("ming");
var cook = document.cookie;
var arr = cook.split("; ");
var uid = 0;
var token1 = 0;
var id =0;
var token = 0;
var name = 0;
for (var i = 0; i < arr.length; i++) {
    var newArr = arr[i].split("=");
    if (newArr[0] == "id") {
        id = newArr[0];
        uid = newArr[1];
    }
    if (newArr[0] == "token") {
        token = newArr[0];
        token1 = newArr[1];
    }
    if (newArr[0] == "usename") {
        name = newArr[0];
        var strr = `
      <a href="login.html" id="ming">${newArr[1]}</a>&nbsp;&nbsp;&nbsp;
      <a href="" id="tc" >退出</a>
      `;
        tui.innerHTML = strr;
        $("#tc").click(function () {
            
            var oDate = new Date();
            oDate.setDate(oDate.getDate() - 1);
            document.cookie = id + "=" + uid + ";expires=" + oDate;
            document.cookie = name + "=" + newArr[1] + ";expires=" + oDate;
            document.cookie = token + "=" + token + ";expires=" + oDate;
            var strr = `
            <a href="login.html" id="ming">请登录</a>
            `;
              tui.innerHTML = strr;
              alert("退出登录！")
        });
    }
}



if (uid != 0) {

    var t = location.search.split("=")[1];
    $.get("http://jx.xuzhixiang.top/ap/api/detail.php", {
        id: t
    }, data => {
        var zhong = document.getElementById("zhong");
        var str = "";
        str += `
        <div class="z-top">
        <h3>${data.data.pname}</h3>
        <p>${data.data.pdesc}</p>
    </div>
    <div class="z-jia">
        <i>价格</i>
        <b>￥</b>
        <span>${data.data.pprice}</span>
    </div>
    <div class="z-dizi">
        <i>运费</i>
        <span>杭州</span>
        <span>上城区</span>
    </div>
    <div class="z-liang">
        <i>累计评价</i>
        <span>4361</span>
    </div>
    <div class="z-xia">
        <div class="zx-lei">
            <span>颜色分类</span>
            <img src="../${data.data.pimg}" alt="">
            <img src="../${data.data.pimg}" alt="">
        </div>
        <div class="zx-shu">
            <span>数量</span>
            <input type="text" value="1" id="liang">
            <div class="zx-jj">
                <span class="iconfont icon-up2" id="jia"></span>
                <span class="iconfont icon-down" id="jian"></span>
            </div>
            <i>件</i>
        </div>
        <div class="zx-btn">
            <div class="mai">
                <a href="">立即购买</a>
            </div>
            <div class="ce" id="ce">
                <a href="">
                    <span class="iconfont icon-gouwuche"></span>
                    加入购物车
                </a>
            </div>
        </div>
        <div class="zx-di">
            <dl>
                <dt>服务承诺</dt>
                <dd>
                    <ul>
                        <li><a href="">正品保障</a></li>
                        <li><a href="">正品保障</a></li>
                        <li><a href="">正品保障</a></li>
                        <li><a href="">正品保障</a></li>
                        <li><a href="">正品保障</a></li>
                        <li><a href="">正品保障</a></li>
                    </ul>
                </dd>
            </dl>
            <div class="zf">
                <p>支付方式
                    <span class="iconfont icon-down"></span>
                </p>
                <div class="qian">
                    <a href="">快捷支付 </a>
                    <a href="">蚂蚁花呗 </a>
                    <a href="">余额宝 </a>
                </div>
            </div>
        </div>
    </div>

        `;

        zhong.innerHTML = str;

        var ce = document.getElementById("ce");
        ce.onclick = function () {
            var liang = document.getElementById("liang");
            $.get("http://jx.xuzhixiang.top/ap/api/add-product.php", {
                uid: uid,
                pid: t,
                pnum: liang.value
            }, data => {
                alert(data.msg);
            });
            return false;
        };
        var jia = document.getElementById("jia");
        var jian = document.getElementById("jian");
        jia.onclick = function () {
            liang.value++;
        }
        jian.onclick = function () {
            if (liang.value <= 1) {
                liang.value = 1;
            } else {
                liang.value--;
            }
        }
    });
}